<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
	</head>
	<body>
		<div class="wrap-container">
				<form class="layui-form" style="width: 90%;padding-top: 20px;">

                    <div class="layui-form-item">
                        <label class="layui-form-label">Id：</label>
                        <div class="layui-input-block">
                            <input type="text" name="label" required lay-verify="required" placeholder="请输入Id" autocomplete="off" class="layui-input positionId" readonly>
                        </div>
                    </div>
					<div class="layui-form-item">
						<label class="layui-form-label">名称：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input positionName">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">描述：</label>
						<div class="layui-input-block">
							<input type="text" name="label" required lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input describtion"  >
						</div>
					</div>
					

					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal updateBtn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary" type="button">重置</button>
						</div>
					</div>
				</form>
		</div>

		<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
		<script>


            if ("${param.positionId}" != null ){
                //获得url后面附带的参数
                var positionId = "${param.positionId}";

            }

			$(document).ready(function(){
                //渲染对应的部门信息
				updatePositionAjax();
			})
			function updatePositionAjax(){
				$.ajax({
					async:true,
					url:"${pageContext.request.contextPath}/Position/getPositionById",
					type:"GET",
					data:{positionId:positionId,
						},
					dataType:"json",
					success:function(result,status,xhr){
                    //将获得的信息返回到数据库
                            $(".positionId").val(result.positionId);
							$(".positionName").val(result.positionName);
                            $(".describtion").val(result.describtion);

					},
					error:function(xhr,status,error){
						alert("异步请求失败!");
					}
				});
			}
            //提交修改的内容
            $(".updateBtn").click(function () {
                var positionId =$(".positionId").val();
                var positionName = $(".positionName").val();
                var describtion =$(".describtion").val();


                $.ajax({
                    async:true,
                    url:"${pageContext.request.contextPath}/Position/updatePositionInfo",
                    type:"post",
                    data:{
                        positionId:positionId,
                        positionName:positionName,
                        describtion:describtion,

                    },
                    dataType:"json",
                    success:function(result,status,xhr){
						if(result == "1"){
							alert("修改成功");
						}else {
							alert("修改失败");
						}

                    },
                    error:function(xhr,status,error){
                        alert("异步请求失败!");
                    }
                });

            })

			$(".layui-btn-primary").click(function () {
				updatePositionAjax();
			});


		</script>
	</body>

</html>